<?php
/*
 * MiniMe - a minimalistic OStatus complient microblogging tool
 * Copyright (C) 2010, Tuomas Koski - koski.tuomas@gmail.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * This object will represent xml element similar to this:
 * <hm:Host>identi.ca</hm:Host>
 * 
 * @author     Tuomas Koski <koski.tuomas@gmail.com>
 * @copyright  Tuomas Koski
 * @license    http://www.gnu.org/licenses/lgpl.txt
 */

class Xrd_HostMeta_Host implements Xrd_ChildElement {
    
    const ELEMENT_HOST = "hm:Host";
    
    private $host;
    
    public function __construct($host) {
        $this->setHost($host);
    } 
    
    public function setHost($host) {
        if(empty($host)) {
            throw new Exception("Host cannot be set empty!");
        }
        $this->host = $host;
    }
    
    public function getHostValue() {
        return $this->host;
    }
    
    /**
     * Creates object from element similar to this: <hm:Host>identi.ca</hm:Host>
     * @param DOMElement $elm
     * @return Xrd_HostMeta_Host 
     */
    public static function buildFromDOMElement(DOMElement $elm) {
        return new Xrd_HostMeta_Host($elm->nodeValue);
    }
    
    /**
     * 
     * @param $dom DOMDocument
     * @return DOMElement
     */
    public function asDOMElement(DOMDocument $dom) {
        return $dom->createElement(self::ELEMENT_HOST, $this->host);
    }
}